/*
 * @Author: gitee_com_zb
 * @Date: 2024-12-04 15:21:07
 * @LastEditors: gitee_com_zb
 * @LastEditTime: 2024-12-04 15:21:22
 * @FilePath: /algorithm/每日一题8.比较版本号(medium).cpp
 * @Description: 题目链接 https://leetcode.cn/problems/compare-version-numbers?envType=problem-list-v2&envId=two-pointers&favoriteSlug=&difficulty=MEDIUM&status=ATTEMPTED%2CSOLVED
 */
class Solution {
public:
    int compareVersion(string version1, string version2) {
        int i = 0, j = 0;
        while (i < version1.size() || j < version2.size()) {
            // 比较当前级别
            int num1 = 0, num2 = 0;
            while (i < version1.size() && version1[i] != '.') 
                num1 = num1 * 10 + (version1[i++] - '0');
            while (j < version2.size() && version2[j] != '.') 
                num2 = num2 * 10 + (version2[j++] - '0');
            if (num1 > num2) return 1;
            if (num1 < num2) return -1;
            i++, j++;; // 跳过'.'到下一个级别
        }
        return 0;
    }
};
